﻿var dayModal = new Vue({
    el: '#dayModal',
    data: {
        sourceName: "",
        quantityName: "",
        year: 1,
        month: 1,
        hourDataSource: null,
        dayDataSource: null,
        hourDataSource2: null,
        sourceSource: null,
        quantitySource: null,
        hourDataCalcMode: 5,
        day: 1,
        usedTimeRange1: false,
        fromValue1: 0,
        toValue1: 23,
        usedTimeRange2: false,
        usedTimeRange2Enable: false,
        fromValue2: 0,
        toValue2: 23,
        usedTimeRange3: false,
        usedTimeRange3Enable: false,
        fromValue3: 0,
        toValue3: 23,
        usedTimeRange4: false,
        usedTimeRange4Enable: false,
        fromValue4: 0,
        toValue4: 23,
    },
    methods: {
        confirm: function () {
            $(this.$refs.dayModal).modal('hide');

            var timeRangeString = "";
            if (this.usedTimeRange1) {
                timeRangeString = timeRangeString + "," + this.fromValue1 + "," + this.toValue1;
            } else {
                timeRangeString = timeRangeString + ",,";
            }
            if (this.usedTimeRange2) {
                timeRangeString = timeRangeString + "," + this.fromValue2 + "," + this.toValue2;
            } else {
                timeRangeString = timeRangeString + ",,";
            }
            if (this.usedTimeRange3) {
                timeRangeString = timeRangeString + "," + this.fromValue3 + "," + this.toValue3;
            } else {
                timeRangeString = timeRangeString + ",,";
            }
            if (this.usedTimeRange4) {
                timeRangeString = timeRangeString + "," + this.fromValue4 + "," + this.toValue4;
            } else {
                timeRangeString = timeRangeString + ",,";
            }
            var functionStr = "=PMEGetDayData(" + this.sourceName + ", " + this.quantityName + "," + this.year + "," + this.month + "," + this.day + "," + this.hourDataCalcMode + timeRangeString + ")";

            ReportDesignerStaticClass.SetActiveCellValue(spreadsheet, functionStr);
        }
    },
    watch: {
        usedTimeRange1: function (newValue, oldValue) {
            // ...
            if (!newValue) {
                this.usedTimeRange2 = false;
                this.usedTimeRange2Enable = false;
            } else {
                this.usedTimeRange2Enable = true;
            }
        },
        usedTimeRange2: function (newValue, oldValue) {
            // ...
            if (!newValue) {
                this.usedTimeRange3 = false;
                this.usedTimeRange3Enable = false;
            } else {
                this.usedTimeRange3Enable = true;
            }
        },
        usedTimeRange3: function (newValue, oldValue) {
            // ...
            if (!newValue) {
                this.usedTimeRange4 = false;
                this.usedTimeRange4Enable = false;
            } else {
                this.usedTimeRange4Enable = true;
            }
        },
        usedTimeRange4: function (newValue, oldValue) {
            // ...
        },
    },
    created: function () {
        var dataModel = new dmyDataModelClass();
        this.hourDataSource = dataModel.getHourDataSource();
        this.dayDataSource = dataModel.getDayDataSource();
        this.hourDataSource2 = dataModel.getHourDataSource2();
        var sourceQuantity = new sourceQuantityClass();
        var that = this;
        sourceQuantity.getsource(function (res) {
            that.$nextTick(function () {
                if (res != null && res != undefined && res.length > 0)
                    for (var i = 0; i < res.length; i++) {
                        res[i] = { id: res[i].Id, name: res[i].Name };
                    }
                this.sourceSource = res;
            });
        });
        sourceQuantity.getquantity(function (res) {
            that.$nextTick(function () {
                if (res != null && res != undefined && res.length > 0)
                    for (var i = 0; i < res.length; i++) {
                        res[i] = { id: res[i].Id, name: res[i].Name };
                    }
                this.quantitySource = res;
            });
        });
        var myDate = new Date();
        var tYear = myDate.getFullYear();
        var tMonth = myDate.getMonth() + 1;
        this.year = tYear;
        this.month = tMonth;
    },
    //directives: {
    //    button_loaded: {
    //        // 指令的定义
    //        inserted: function (el) {
    //            el.textContent = "success";
    //            el.onclick = function () { alert("运行的jquery版本是：" + $().jquery); }
    //        }
    //    }
    //}
})